<?php

namespace YmPhp\Admin\Http\Actions\Extensions;

use YmPhp\Admin\Admin;
use YmPhp\Admin\Grid\RowAction;

class Update extends RowAction
{
    public function title()
    {
        $replace = ['version' => $this->row->extension->getLocalLatestVersion()];

        if ($this->row->version == 0){
            $version = '安装';
        }else{
            $version = sprintf('<b>%s</b>', trans('admin.upgrade_to_version', $replace));
        }

        return $version;
    }

    public function handle()
    {
        $manager = Admin::extension()
            ->updateManager()
            ->update($this->getKey());

        return $this
            ->response()
            ->success(implode('<br>', $manager->notes))
            ->refresh();
    }
}
